package com.wqtz.chechai.view.activities;

import android.content.Intent;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.wqtz.chechai.R;
import com.wqtz.chechai.base.BaseActivity;
import com.wqtz.chechai.bean.BreakReceiptData;
import com.wqtz.chechai.presenter.BasePresent;
import com.wqtz.chechai.utils.LogUtils;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 项目名称： CheChai
 * 创建人 :  Kisum
 * 创建时间: 2017/2/6
 */
public class UploadBreakReceiptActivity extends BaseActivity {
    @BindView(R.id.iv_back)
    ImageView mIvBack;
    @BindView(R.id.tv_has_receipt)
    TextView mTvHasReceipt;
    @BindView(R.id.btn_confirm)
    Button mBtnConfirm;
    @BindView(R.id.rl_upload_break_receipt)
    RelativeLayout mRlUploadBreakReceipt;
    //解约审核中
    private final int BREAK_CHECKING = 7;


    @Override
    public void init() {
        ButterKnife.bind(this);
        //注册EventBus
        EventBus.getDefault().register(this);
    }

    @Override
    public void loadData() {

    }

    @Override
    public int setContentViews() {
        return R.layout.activity_break_receipt;
    }

    @Override
    public BasePresent createPresenter() {
        return null;
    }

    @OnClick({R.id.iv_back, R.id.rl_upload_break_receipt, R.id.btn_confirm})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.iv_back:
                this.finish();
                break;
            //上传解约回单
            case R.id.rl_upload_break_receipt:
                Intent toUpLoadBreakReceiptPicIntent = new Intent(this, UpLoadBreakReceiptPicActivity.class);
                startActivity(toUpLoadBreakReceiptPicIntent);
                break;
        }
    }

    //订阅者订阅EventBus事件,在主线程执行，更新UI
    @Subscribe(threadMode = ThreadMode.MAIN)
    public void receiveImagePath(BreakReceiptData breakReceiptData) {
        ArrayList<String> imagePath = breakReceiptData.getList();
        LogUtils.e("imagePath:" + imagePath);
        if (imagePath.size() == 0) {
            mTvHasReceipt.setVisibility(View.INVISIBLE);
            mBtnConfirm.setClickable(false);
            mBtnConfirm.setBackgroundResource(R.drawable.shape_login_btn_default);
        } else {
            mTvHasReceipt.setVisibility(View.VISIBLE);
            mBtnConfirm.setBackgroundResource(R.drawable.selector_activity_login_btn);
            btnConfirm();
        }

    }
    //确认
    private void btnConfirm() {
        mBtnConfirm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent toLoanInfoIntent = new Intent(UploadBreakReceiptActivity.this, LoanInfoActivity.class);
                toLoanInfoIntent.putExtra("type",BREAK_CHECKING);
                startActivityForResult(toLoanInfoIntent,BREAK_CHECKING);
                finish();
            }
        });
    }
    @Override
    protected void onResume() {
        super.onResume();
        activitys.add(this); //添加当前的activity

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }

}
